Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add null check and fallback to document.getSelection to handle firefo… #5

Merged
merged 1 commit into from
Apr 7, 2017
Merged

add null check and fallback to document.getSelection to handle firefo… #5

merged 1 commit into from
Apr 7, 2017

Conversation

utanapishtim
Copy link

On firefox 45.7.0 win.contentWindow.getSelection() returns call causing two issue in clipboard-copy:

  1. The current selection is not updated and the intended text is not copied to the clipboard
  2. The call to selection.removeAllRanges() outside of the try-catch block throws a TypeError and the iframe is never removed from the document, causing a spooky contentless-border to appear!

The fix for this seems to be a null check on the return of win.contentWindow.getSelection and falling back to document.getSelection if the check check succeeds.

I checked if replacing win.contentWindow.getSelection with document.getSelection succeeds in all cases, but it fails to copy the desired contents in at least chrome 56.0.2924.87.

This fix passes all tests, adds a line, and bumps the byte count by approximately 59 bytes.

…x 45.7.0 iframe.windowContent.getSelection() returning null
@feross
Copy link
Owner

feross commented Apr 7, 2017

This doesn't actually work for me on Firefox. I found a difference approach that I confirmed works on Firefox, Chrome, Safari, Brave, and Edge. So that's what I released as 1.2.0.

@utanapishtim
Copy link
Author

Awesome, thanks you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants